import React, {Component} from 'react';
import ReactDom from 'react-dom';
import { FormattedMessage, injectIntl } from 'react-intl';
import {actions} from "mirrorx";
import {InputNumber, Select, Button, Modal, Message} from "tinper-bee";
import Radio from 'bee-radio';
import moment from 'moment'
import DatePicker from "bee-datepicker";
import FormError from 'components/FormError';
import RefComponent from 'components/RefComponent';
import FormList from 'components/FormList'

let {RangePicker} = DatePicker;

import './index.less'

const FormItem = FormList.Item;

class CreateCustomer extends Component {
    constructor(props) {
        super(props);
        this.state = {
        }

    }
    

    createCustomer = (delFlag) => {
        let { selectData } = this.props;
    
        if (delFlag) {
            this.props.form.validateFields((err, _values) => {
                let supplierCategoryId = _values.supplierCategoryId && JSON.parse(_values.supplierCategoryId).refpk;
                if(!supplierCategoryId) {
                    err = true;
                }
                if(err) {
                    Message.create({ content: '请输入值', color: 'warning' });
                }else {
                    let param = {
                        supplierCateId:supplierCategoryId,
                        id:selectData[0].id
                    }
                    actions.PromoterLeaveApplication.createCustomer(param);
                    this.props.closeCreateModal();
                }
                
            })

            
            
        }else {
            this.props.closeCreateModal();
        }
        

    }


    render() {
        let {form,onCallback,showCreateCustomerModal} = this.props;
        let { getFieldProps, getFieldError } = this.props.form;

        let self = this;
        return (
            <Modal
            show={showCreateCustomerModal}
            onHide={this.createCustomer} >
            <Modal.Header>
                <Modal.Title>生成供应商</Modal.Title>
            </Modal.Header>

            <Modal.Body>
                <FormItem 
                    label={'生成供应商'}
                    FormError = {<FormError errorMsg={getFieldError(`supplierCategoryId`)} />}
                >
                        <RefComponent
                            ref="createCustomer" 
                            title={"供应商基本分类"}
                            refName={"categorySupplierRef"}
                            fieldName={"supplierCategoryId"}
                            //initialValue={'{refpk:"",refname:""}'}
                            constparam = {{}}
                            aliasparam = {""}
                            childType = {""}
                            clearMatchData={this.clearMatch}
                            form={this.props.form}
                        />

                </FormItem>
            </Modal.Body>

            <Modal.Footer>
                <Button onClick={() => this.createCustomer(false)} style={{ marginRight: 10 }}><FormattedMessage id="js.Ref.Ref224.0012" defaultMessage="关闭" /></Button>
                <Button onClick={() => this.createCustomer(true)} ><FormattedMessage id="js.com.Pas.0005" defaultMessage="确定" /></Button>
            </Modal.Footer>
        </Modal>

        )
    }
}

export default FormList.createForm()(injectIntl(CreateCustomer))
